
namespace System.Collections
{
    public static class ByteArrayExtentions
    {
        public static short[] ToInt16Array(this byte[] array)
        {
            var result = new short[array.Length / 2];

            for(var i = 0; i < array.Length / 2; i++)
                result[i] = BitConverter.ToInt16(array, i * 2);

            return result;
        }

        public static int[] ToInt32Array(this byte[] array)
        {
            var result = new int[array.Length / 4];

            for(var i = 0; i < array.Length / 4; i++)
                result[i] = BitConverter.ToInt32(array, i * 4);

            return result;
        }

        public static int ToInt(this byte[] array)
        {
            var result = 0;
            unchecked
            {
                for(var i = 0; i < array.Length; i++)
                    result += array[i] << (8 * i);
            }
            return result;
        }
    }
}